package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-06-01 01:22
 */
public class DistributeCandies {

    public int[] distributeCandies(int candies, int num_people) {

        int[] dCandies = new int[num_people];
        int i = 0, pre = 0;
        while (candies != 0) {
            if (i == dCandies.length) {
                i = 0;
            }
            pre = pre + 1;
            candies -= pre;
            if (candies < 0) {
                dCandies[i] = candies + pre + dCandies[i];
                break;
            } else {
                dCandies[i++] = pre + dCandies[i-1];
            }

        }
        return dCandies;
    }

    public static void main(String[] args) {
        new DistributeCandies().distributeCandies(10,3);
    }
}
